<?php

class PaperstatusController extends Zend_Controller_Action 
{
    protected $_model;

    public function init()
    {
        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('view', 'html')
                    ->addActionContext('comment', 'html')                    
                    ->initContext();
    }
    
    public function indexAction()
    {
        
    }
    
    public function allAction()
    {
    	$request = $this->getRequest();
    	$callback = $request->getParam('callback');
        $model = $this->getPaperStatus();
        $start = $request->getParam('start');
        $limit = $request->getParam('limit');
     	$count = $total = $model->getTotal();
        $statuses = $model->getStatuses($start, $limit);
        $json = array();
        $json['totalCount'] = $count;
        $json['statuses'] = $statuses;
        echo $callback.'('.Zend_Json::encode($json).')';
        die();
    }

    public function editAction()
    {			
        $request = $this->getRequest();
		$data = $request->getParams();
		$model = $this->getPaperStatus();
        $model->save($data);        
        die();        
    }		
    
    public function deleteAction(){
    	$model = $this->getPaperStatus();
        $request = $this->getRequest();
        $id = $request->getParam('id'); 
        $model->deleteStatus($id);
    	die();
    }    
  
  
    protected function getPaperStatus()
    {
        if (null === $this->_model) {
            require_once APPLICATION_PATH . '/models/PaperStatus.php';
            $this->_model = new Model_PaperStatus();
        }
        return $this->_model;
    }
	
   
}
